import axios from "~/axios";

export function login(username, password) {
  return axios.post("/login", {
    username,
    password,
  });
}

export function getinfo() {
  return axios.get("/admin/getinfo");
}

export function logout() {
  return axios.post("/loginOut");
}

export function updatepassword(data) {
  return axios.post("/admin/updatepassword", data);
}

//获取管理员列表

export function getManagerList(page, query = {}) {
  let q = [];
  for (const key in query) {
    if (query[key]) {
      q.push(`${key}=${encodeURIComponent(query[key])}`);
    }
  }
  let r = q.join("&");
  r = r ? "&" + r : "";
  return axios.get(`/getadmin?page=${page}${r}`);
}

export function createManager(data) {
  return axios.post(`/register`, data);
}

export function updateManager(id, data) {
  return axios.post(`/updatePassword?id=${id}`, data);
}

export function deleteManager(id) {
  return axios.delete(`deleteadmin/${id}`);
}
